package com.lanou.sfu.songforu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.sfu.songforu.R;
import com.lanou.sfu.songforu.datas.SearchMV;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by quyan on 15/10/29.
 * mv适配器
 */
public class SearchMVAdapter extends BaseAdapter {
    private Context context;
    private List<SearchMV.DataEntity> datas;

    public SearchMVAdapter(Context context, List<SearchMV.DataEntity> dataEntities) {
        this.context = context;
        this.datas = dataEntities;
    }

    @Override
    public int getCount() {
        return datas != null && datas.size() > 0 ? datas.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.searching_mv,null);
            holder = new ViewHolder();
            holder.commentNum = (TextView) convertView.findViewById(R.id.comment_num);
            holder.mvAuthor = (TextView) convertView.findViewById(R.id.mv_author);
            holder.mvImg = (ImageView) convertView.findViewById(R.id.mv_img);
            holder.mvName = (TextView) convertView.findViewById(R.id.mv_name);
            holder.mvNum = (TextView) convertView.findViewById(R.id.mv_num);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        SearchMV.DataEntity dataEntity = (SearchMV.DataEntity) getItem(position);
        holder.mvAuthor.setText(dataEntity.getSingerName());
        holder.commentNum.setText(dataEntity.getBulletCount());
        holder.mvNum.setText(dataEntity.getPickCount());
        holder.mvName.setText(dataEntity.getVideoName());
        Picasso.with(context).load(dataEntity.getPicUrl()).into(holder.mvImg);
        return convertView;
    }

    public class ViewHolder{
        private ImageView mvImg;
        private TextView mvName;
        private TextView mvAuthor;
        private TextView mvNum;
        private TextView commentNum;
    }
}
